/*
This is the script that will be used to migrate the database from revision 9 to revision 10.

You can customize the script, and your edits will be used in deployment.
The following objects will be affected:
  agency.ConfigurationType
*/

SET NUMERIC_ROUNDABORT OFF
GO
SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT, QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
PRINT N'Dropping foreign keys from [agency].[Configuration]'
GO
ALTER TABLE [agency].[Configuration] DROP CONSTRAINT[FK_Configuration_ConfigurationType]
GO
PRINT N'Dropping constraints from [agency].[ConfigurationType]'
GO
ALTER TABLE [agency].[ConfigurationType] DROP CONSTRAINT [PK_ConfigurationType]
GO
PRINT N'Rebuilding [agency].[ConfigurationType]'
GO
CREATE TABLE [agency].[tmp_rg_xx_ConfigurationType]
(
[ConfigurationTypeId] [int] NOT NULL IDENTITY(1, 1),
[Name] [nvarchar] (256) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Code] [nvarchar] (max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ParentConfigurationTypeId] [int] NULL,
[Active] [bit] NOT NULL,
[Deleted] [bit] NOT NULL,
[CreatedBy] [int] NOT NULL,
[CreatedOn] [datetime] NOT NULL,
[ModifiedBy] [int] NULL,
[ModifiedOn] [datetime] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET IDENTITY_INSERT [agency].[tmp_rg_xx_ConfigurationType] ON
GO
INSERT INTO [agency].[tmp_rg_xx_ConfigurationType]([ConfigurationTypeId], [Name], [Code], [Active], [Deleted], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) SELECT [ConfigurationTypeId], [Name], [Code], [Active], [Deleted], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn] FROM [agency].[ConfigurationType]
GO
SET IDENTITY_INSERT [agency].[tmp_rg_xx_ConfigurationType] OFF
GO
DECLARE @idVal BIGINT
SELECT @idVal = IDENT_CURRENT(N'[agency].[ConfigurationType]')
IF @idVal IS NOT NULL
    DBCC CHECKIDENT(N'[agency].[tmp_rg_xx_ConfigurationType]', RESEED, @idVal)
GO
DROP TABLE [agency].[ConfigurationType]
GO
EXEC sp_rename N'[agency].[tmp_rg_xx_ConfigurationType]', N'ConfigurationType'
GO
PRINT N'Creating primary key [PK_ConfigurationType] on [agency].[ConfigurationType]'
GO
ALTER TABLE [agency].[ConfigurationType] ADD CONSTRAINT [PK_ConfigurationType] PRIMARY KEY CLUSTERED  ([ConfigurationTypeId]) ON [PRIMARY]
GO
PRINT N'Adding foreign keys to [agency].[Configuration]'
GO
ALTER TABLE [agency].[Configuration] ADD CONSTRAINT [FK_Configuration_ConfigurationType] FOREIGN KEY ([ConfigurationTypeId]) REFERENCES [agency].[ConfigurationType] ([ConfigurationTypeId])
GO
